package learnrxjava.examples;

import java.util.ArrayList;

import rx.Observable;
import rx.Scheduler;
import rx.schedulers.Schedulers;

public class ScanVsReduceExample {


    public static void main(String... args) {
        //循环操作服务
        Observable.range(0, 10).subscribeOn(Schedulers.io()).reduce(new ArrayList<>(), (list, i) -> {
            list.add(i);
            return list;
        }).forEach(System.out::println);
        System.out.println("... vs ...");
        Observable.range(0, 10).scan(new ArrayList<>(), (list, i) -> {
            list.add(i);
            return list;
        }).forEach(System.out::println);
    }
}
